Skip to main content

Timeframe Presets Repository

Repository for storing Timeframe Presets list.

Repository interface:

/**
* Interface for a repository to store data about the selected timeframe on the chart.
*
* Implementation of this interface is mandatory for the library to function. It is passed to [com.devexperts.dxcharts.lib.domain.DxChartsConfig].
*
* Standard implementation: [com.devexperts.dxcharts.lib.data.repo.default_repos.DefaultTimeframePresetsRepository]
*/
interface TimeframePresetsRepository {
/**
* Method to retrieve a list of user-created and standard timeframes.
*/
fun getItems(): List<TimeframePreset>
/**
* Method to set a timeframe as selected.
*/
fun select(value: TimeframePreset)
/**
* Method to get the selected timeframe.
*/
fun getSelected(): TimeframePreset?
}

TimeframePreset class used in the repository:

/**
* Data-class for storing data about timeframes presets
*
* @property name Name of the preset
* @property nameRes String resource with name of the preset, could be null
* @property range Range of the preset in milliseconds
*/
data class TimeframePreset(
val name: String,
@StringRes val nameRes: Int? = null,
val range: Long,
val aggregation: Aggregation
) {
/**
* Storing constants for default timeframes presets
*/
object Range {
const val HOUR = 60L * 60L * 1000L
const val DAY = 24L * HOUR
const val WEEK = 7L * DAY
const val MONTH = 30L * DAY
const val MONTH_3 = 90L * DAY
const val MONTH_6 = 180L * DAY
const val YEAR = 365 * DAY
}
}